package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.elas.ElasticsearchDao;
import com.baizhi.cmfz.entity.Articel;
import com.baizhi.cmfz.service.ArticelService;
import com.baizhi.cmfz.service.CmfzElasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CmfzElasServiceImpl implements CmfzElasService {
	@Autowired
	private ElasticsearchDao elasticsearchDao;
	@Resource
	private ArticelService articelService;
	@Override
	public Boolean createIndex() {
		Map map = articelService.selectArticelPage(1, 100, null);
		List<Articel>data = (List<Articel>) map.get("data");
		elasticsearchDao.saveAll(data);
		return true;
	}

	@Override
	public Boolean deleteIndex() {
//		删除
		elasticsearchDao.deleteAll();
		return true;
	}

	@Override
	public List<Articel> selectIndex(String name,String keywords) {
		List<Articel> aLlByArticelNameOrArticelContent = elasticsearchDao.findALlByArticelNameOrArticelContent(keywords, keywords);
		return aLlByArticelNameOrArticelContent;

	}
}
